﻿<?php

/**
 * Базовый класс для работы с исключениями
 * @author Yura
 *
 */
class ErrorList extends Exception{	
	public function __construct($errorlist,$error_type,$param=NULL){
		$message = '';
		if(!isset($errorlist[$error_type])){
			$message = 'Thrown error is not described. Error num: '.$error_type;
		}
		elseif($param === NULL) $message = $errorlist[$error_type];
		elseif(!is_array($param)){
			$message = preg_replace("/%s/",$param,$errorlist[$error_type],1);
			if($message === NULL) $message = 'Wrong error throwing. Error num: '.$error_type;
		}
		else{
			foreach($param as $value){
				$message = preg_replace("/%s/",$value,$message,1);
				if($message === NULL){
					$message = 'Wrong error throwing. Error num: '.$error_type;
					break;
				}
			}
		}
		parent::__construct($message);
	}	
}

?>